-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-1378: Make BulkWrite enumerate requests argument only once #1298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -174,7 +174,7 @@ public class Acknowledged : BulkWriteResult<TDocument> | |||
|
|||
// constructors | |||
/// <summary> | |||
/// Initializes a new instance of the <see cref="Acknowledged" /> class. | |||
/// Initializes a new instance of the <see cref="BulkWriteResult{TDocument}.Acknowledged" /> class. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not related to the PR itself, but it fixes some warnings we got on build
@@ -218,27 +218,30 @@ public override BulkWriteResult<TDocument> BulkWrite(IEnumerable<WriteModel<TDoc | |||
public override BulkWriteResult<TDocument> BulkWrite(IClientSessionHandle session, IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options, CancellationToken cancellationToken = default(CancellationToken)) | |||
{ | |||
Ensure.IsNotNull(session, nameof(session)); | |||
Ensure.IsNotNull(requests, nameof(requests)); | |||
if (!requests.Any()) | |||
Ensure.IsNotNull((object)requests, nameof(requests)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This unnecessary cast to object needed to make code analysis happy, otherwise it says we might be doing multiple enumeration of the requests
|
||
var result = async ? await subject.BulkWriteAsync(wrappedRequests) : subject.BulkWrite(wrappedRequests); | ||
|
||
result.Should().NotBeNull(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically we testing here is there were no exception, as wrappedRequests
will throw on second attempt to enumerate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -234,7 +234,7 @@ internal static MongoBulkWriteException<TDocument> FromCore(MongoBulkWriteOperat | |||
|
|||
return new MongoBulkWriteException<TDocument>( | |||
ex.ConnectionId, | |||
BulkWriteResult<TDocument>.FromCore(ex.Result, processedRequests), | |||
BulkWriteResult<TDocument>.FromCore(ex.Result, processedRequests.ToList()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider ToArray
|
||
namespace MongoDB.Driver.TestHelpers | ||
{ | ||
public static class OnlyOnceEnumerable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider counting enumerations instead of throwing here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
if (!requests.Any()) | ||
Ensure.IsNotNull((object)requests, nameof(requests)); | ||
|
||
var requestList = requests.ToArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: requestsArray
No description provided.